package ai

import (
	"context"
	"gitee.com/dn-jinmin/langchaingo"
	"github.com/tmc/langchaingo/memory"

	"gitee.com/dn-jinmin/chatcms/internal/svc"
	"github.com/tmc/langchaingo/chains"
	"github.com/tmc/langchaingo/schema"
)

type Ai struct {
	*Reference
	*Answer
	svc   *svc.ServiceContext
	agent chains.Chain
}

func NewAi(svc *svc.ServiceContext) *Ai {
	//tools := []tools.Tool{
	//	NewAnswer(svc),
	//	NewReference(svc),
	//}

	return &Ai{
		svc:       svc,
		Reference: NewReference(svc),
		Answer:    NewAnswer(svc),
		//agent: agents.NewExecutor(agents.NewOneShotAgent(
		//	svc.DefaultLLM,
		//	tools,
		//	agents.WithPromptPrefix(_defaultMrklPrefix),
		//	agents.WithPromptFormatInstructions(_defaultMrklFormatInstructions),
		//	agents.WithPromptSuffix(_defaultMrklSuffix),
		//	agents.WithCallbacksHandler(svc.Callback),
		//)),
	}
}

func (a *Ai) Call(ctx context.Context, inputs map[string]any, options ...chains.ChainCallOption) (map[string]any, error) {
	// 先获取到对应的参考信息
	ref, err := a.Reference.Call(ctx, inputs["input"].(string))
	if err != nil {
		return nil, err
	}

	return map[string]any{
		langchaingo.OutPutKey: ref,
	}, nil
}

func (a *Ai) GetMemory() schema.Memory {
	return memory.NewSimple()
}

func (a *Ai) GetInputKeys() []string {
	return nil
}
func (a *Ai) GetOutputKeys() []string {
	return nil
}
